\subsection{Resolver}\label{spec:format:resolver}


\begin{definition}[Resolver]\label{def:resolver}
\begin{lstlisting}[language=buzz1]
// /resolver

define type resolver 
    api url
    address ethereum/address
    tlds []string 

define function resolve @host []byte through @resolver
as
    @tld = @host split on '.'' last    @resolver = @resolvers any tlds any ==  @tld
        
    ethereum/call "getContentHash" of @host using @resolver api at @resolver address
        as address
                     
\end{lstlisting}
\end{definition}




\subsection{Pinning}\label{spec:format:pinning}


\begin{definition}[Pinning]\label{def:pinning}
\begin{lstlisting}[language=buzz1]
// /pin

define type pin
    reference
    chunks uint64
    
define function list
    return []pin
has api GET "/pin/"

define function view reference
    return uint64
has api GET "/pin/<reference>"
    
define function pin reference
    return uint64
has api PUT "/pin/<reference>"

define function pin reference
    return uint64
has api DELETE "/pin/<reference>"
    
       
\end{lstlisting}
\end{definition}



\subsection{Tags}\label{spec:format:tags}


\begin{definition}[Tags]\label{def:tags}
\begin{lstlisting}[language=buzz1]
// /tag

define type tag
    id     [segment size]byte
    reference     // the current root
    complete bool // if local upload finished
    total  uint64 // number of chunks expected
    split  uint64 // number of chunks split
    stored uint64 // number of chunks stored locally
    seen   uint64 // number of chunks already in db
    sent   uint64 // number of chunks sent with push-sync
    synced uint64 // number of chunks synced


define function list
    return []tag
has api GET "/tag/"

define function view reference
    return uint64
has api GET "/tag/<reference>"
    
define function add reference
    return uint64
has api POST "/tag/"

define function remove reference
    return uint64
has api DELETE "/tag/<reference>"
    
       
\end{lstlisting}
\end{definition}

\subsection{Storage}\label{spec:format:bzz-api}


\begin{definition}[Public storage API]\label{def:bzz}
\begin{lstlisting}[language=buzz1]
// /bzz

define function upload @data stream of byte
has api POST on "bzz:/<host>/<path>" from @data as body
as
    @root = resolver/resolve @host
    @manifest = access/unlock @root
    @entry = file/upload @data
    @reference =  chunk/store @entry as []byte
    manifest/add @reference to @manifest on @path


define function download @path []byte     from @host []byte
has api POST on "bzz:/<host>/<path>" from @data as body
as
    @root = resolver/resolve @host
    @manifest = access/unlock @root
    @entry = manifest/lookup @path in @manifest
    file/download @entry reference
\end{lstlisting}
\end{definition}
